package com.servlet;

import com.dao.imp.FindGoodsDaoImp;
import net.sf.json.JSONArray;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/12/2 18:20
 **/

@WebServlet(name = "GetOrderByNameServlet", value = "/GetOrderByNameServlet")
public class GetOrderByNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String good_name = request.getParameter("keyword");

        FindGoodsDaoImp findGoodsDaoImp = new FindGoodsDaoImp();
        String sql = "select * from goods where status=1 and good_name LIKE '%" + good_name + "%'";
//        System.out.println(sql);
        List goodList = findGoodsDaoImp.getGoodList(sql);
//        System.out.println(goodList.size());
        JSONArray json = JSONArray.fromObject(goodList);
        response.getWriter().print(json);


    }
}
